<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStudentTable extends Migration
{
    public function up()
    {
        /**
         * 姓名，性别，民族，曾用名，
         * 出生年月，学籍号，所在班级，
         * 身份证号码，户籍地，国籍，
         * 港澳台外(是否)，是否独生子女，
         * 是否寄宿，是否受过学前教育，
         * 是否留守儿童，家庭住址，现住址
         */
        Schema::create('student', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name','64')->comment('姓名');
            $table->string('sex','64')->default('F')->comment('性别 参考系统代码SEX');
            $table->string('nation','64')->default('汉族')->comment('名族');
            $table->string('old_name','64')->default('')->comment('曾用名');
            $table->date('born_date')->nullable()->comment('出生日期');
            $table->string('census_no',128)->default('')->comment('学籍号');
            $table->bigInteger('clbum_id')->default('0')->comment('所在班级');
            $table->string('id_card',128)->comment('身份证号');
            $table->string('hometown',64)->default('')->comment('户籍地');
            $table->string('citizenship',64)->default('中国')->comment('国籍');
            $table->tinyInteger('is_macao_or_taiwan')->default('0')->comment('港澳台外(是否)');
            $table->tinyInteger('is_only_child')->default('0')->comment('是否独生子女');
            $table->tinyInteger('is_lodge')->default('0')->comment('是否寄宿');
            $table->tinyInteger('is_learn_preschool')->default('0')->comment('是否受过学前教育');
            $table->tinyInteger('is_leftover_child')->default('0')->comment('是否留守儿童');
            $table->string('home_address',128)->default('')->comment('家庭住址');
            $table->string('now_address',128)->default('')->comment('现住址');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->string('updated_user',64)->default('')->comment('修改人');
            $table->unique('id_card','uniq_id_card');
            $table->timestamps();
        });
        /**
         * 学生家庭关系
         * 关系、姓名、联系电话、工作单位
         */
        Schema::create('student_relation', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('student_id');
            $table->string('relation_name','16')->default('')->comment('关系');
            $table->string('name','16')->default('')->comment('姓名');
            $table->string('phone','16')->default('')->comment('电话');
            $table->string('company','128')->default('')->comment('工作单位');
            $table->string('created_user',64)->comment('创建人');
            $table->string('updated_user',64)->comment('修改人');
            $table->timestamps();
        });

        /**
         * 学生简历
         * student_resume
         * 学习开始时间、学习终止时间、学习单位、学习内容、担任职务、学习证明人
         */
        Schema::create('student_resume', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('student_id');
            $table->date('start_date')->comment('开始时间');
            $table->date('end_date')->comment('结束时间');
            $table->string('organization')->default('')->comment('学习单位');
            $table->string('content')->default('')->comment('学习单位');
            $table->string('title','64')->default('')->comment('职位');
            $table->string('certifier','64')->default('')->comment('证明人');
            $table->string('created_user',64)->comment('创建人');
            $table->string('updated_user',64)->comment('修改人');
            $table->timestamps();
        });

        /**
         * 学籍变更
         * 时间、变更前、变更后
         */
        Schema::create('student_school_census_change', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('student_id');
            $table->date('change_date')->comment('变更时间');
            $table->string('before_change')->default('')->comment('变更前学籍');
            $table->string('after_change')->default('')->comment('变更后学籍');
            $table->string('created_user',64)->comment('创建人');
            $table->string('updated_user',64)->comment('修改人');
            $table->timestamps();
        });


    }

    public function down()
    {
        Schema::drop('student');
        Schema::drop('student_relation');
        Schema::drop('student_resume');
        Schema::drop('student_school_census');
    }
}
